<html>
	<?php
		require_once("classes/User.php");
		require_once("classes/Database.php");
		require_once("classes/Head.php");
		require_once("classes/Section.php");
		require_once("classes/Image.php");
		require_once("classes/Title.php");
		require_once("classes/Paragraph.php");
		require_once("classes/LinkList.php");
		require_once("classes/Table.php");
		require_once("classes/Qualification.php");
		require_once("classes/Experience.php");
		require_once("classes/EntryList.php");
		
		session_start();
		
		$head = new Head();
		$userSession = $_SESSION["user"];
		
		if(isset($_GET["candidate"])){
			$id = $_GET["candidate"];
			$db = new Database("localhost", "root", "");
			$db->connect("emprego");
			$db->executeQuery("SELECT * FROM users WHERE id='$id'");
			if($line = $db->getResultLine(MYSQL_ASSOC)){
				$user = new User();
				$user->setId($line["id"]);
				$user->setName($line["nome"]);
				$user->setEmail($line["email"]);
				$user->setRole($line["roles"]);
			}else{
				$user = $userSession;
			}
		}else{
			$user = $userSession;
		}
		
		if($_SESSION["login"]){
			$title = "Ver Curriculum";
		}else{
			$title = "Login Errado";
		}
		$head->addLayout("css/style.css");
		$head->addTitle($title);
		
		$head->printHead();
	?>
	<body id="body">
		<div id="struture">
			<div id="container">
		        <?php
		        	$header = new Section("header");					
						$header->addElement(new Image("images/job.png", "logo", "100px", "100px"));
						
						$title = new Title("Ofertas de Emprego", "title");
						$header->addElement($title);
					$header->printSection();

					$db = new Database("localhost", "root", "");
					$db->connect("emprego");
					$id = $user->getId();
					$db->executeQuery("SELECT * FROM curriculum WHERE id='$id'");
					$line = $db->getResultLine(MYSQL_ASSOC);
		        	
		        	/* Left Page */
		        	$leftPage = new Section("leftPage");
					if(!$_SESSION["login"]){
						$leftPage->addElement(new Title("Erro", "menuTitle"));
						$leftPage->addElement(new Paragraph("Login Errado", "menu"));
					}else{
						if(!$line){
							$leftPage->addElement(new Title("Erro", "menuTitle"));
							$leftPage->addElement(new Paragraph("Ainda n&atildeo criou um Curriculum.", "menu"));
						}else{
							$leftPage->addElement(new Title("Candidato", "menuTitle"));
							$leftPage->addElement(new Paragraph("Confira os dados do curriculum.", "menu"));
						}
						$voltar = new LinkList("menuEntry");
						$voltar->addLink("Voltar", "home.php", new Image("images/leave.png", "icon", "16px", "16px"));
						$leftPage->addElement($voltar);
					}
					$leftPage->printSection();

					$content = new Section("content");
					if($_SESSION["login"]){
						if(!$line){
							$content->addElement(new Title("Erro", "seccaoTitle"));
						}else{
							$content->addElement(new Title("Curriculum de ".$user->getName(), "seccaoTitle"));
							$cat = $line["category"];
							$db->executeQuery("SELECT name FROM category WHERE id='$cat'");
							$line2 = $db->getResultLine(MYSQL_ASSOC);
							$geralEntry = new EntryList("entry");
							$geralEntry->openEntry();
							$geralEntry->addTitle("Dados Gerais");
							$geralEntry->addEntry("Categoria:", $line2["name"]);
							$geralEntry->addEntry("Descri&ccedil&atildeo:", $line["description"]);
							$geralEntry->closeEntry();
							$content->addElement($geralEntry);
							
							$content->addHtmlCode("</br></br>");
							$content->addElement(new Title("Habilita&ccedil&otildees", "simpleTitle"));
							$tableQualifications = new Table(array('Escola', 'Curso', 'Data Inicio', 'Data Fim'), "dataTable");
							$qualification = new Qualification("", "", "", "", "");
							while(($qualification->findByCurriculum($user->getId())) != 0){
								$array = array($qualification->getSchool(), $qualification->getCourse(), $qualification->getStartDate(), $qualification->getEndDate());
								$tableQualifications->addRow($array);
							}
							$content->addElement($tableQualifications);
							
							$content->addHtmlCode("</br></br>");
							$content->addElement(new Title("Experi&ecircncia", "simpleTitle"));
							$tableExperiences = new Table(array('Empresa', 'Actividade', 'Data Inicio', 'Data Fim'), "dataTable");
							$experience = new Experience("", "", "", "", "");
							while(($experience->findByCurriculum($user->getId())) != 0){
								$array = array($experience->getEnterprise(), $experience->getActivity(), $experience->getStartDate(), $experience->getEndDate());
								$tableExperiences->addRow($array);
							}
							$content->addElement($tableExperiences);
						}
					}else{
						$content->addElement(new Title("Erro", "seccaoTitle"));
					}
					
					$content->printSection();
					
					$footer = new Section("footer");
						$text = new Paragraph("Copyright&copy Nuno Pombo", "");
						$footer->addElement($text);
					$footer->printSection();
		        ?>
			</div>
		</div>
	</body>
</html>